/*
 * This class generates the administrative UI
 */

/*
 * AdministratorConsole.java
 *
 * Created on 21-Mar-2011, 12:23:53 PM
 */

package pos.ui.screen.administrator;

import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import pos.ui.screen.Logout;

/**
 *
 * @author rsrikanth
 */
public class AdministratorConsole extends javax.swing.JFrame implements TreeSelectionListener {

    /** Creates new form AdministratorConsole */
    public AdministratorConsole() {
        initComponents();
        addJTree();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Adminstrator Console");

        jSplitPane1.setDividerLocation(250);

        jScrollPane1.setMinimumSize(new java.awt.Dimension(23, 30));
        jSplitPane1.setLeftComponent(jScrollPane1);

        jScrollPane2.setMinimumSize(new java.awt.Dimension(700, 600));
        jSplitPane1.setRightComponent(jScrollPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AdministratorConsole().setVisible(true);
            }
        });
    }

    public void valueChanged(TreeSelectionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        if(node == null){
            return;
        }
        if (node.isLeaf()) {
            Object nodeInfo = node.getUserObject();
//            System.out.println(nodeInfo.toString());
            if(!nodeInfo.toString().equalsIgnoreCase("Logout"))
                jScrollPane2.setViewportView((JPanel)nodeInfo);
            else
                new Logout(this);
        }
    }
    public void addJTree(){
         //Create the nodes.
        DefaultMutableTreeNode root =
            new DefaultMutableTreeNode("Adminstrator View");
        createNodes(root);

        //Create a tree that allows one selection at a time.
        tree = new JTree(root);
        tree.getSelectionModel().setSelectionMode
                (TreeSelectionModel.SINGLE_TREE_SELECTION);

        //Listen for when the selection changes.
        tree.addTreeSelectionListener(this);
        jScrollPane1.setViewportView(tree);
        
    }
    private void createNodes(DefaultMutableTreeNode root) {
        
        DefaultMutableTreeNode itemnode = new DefaultMutableTreeNode("ManageItems");
        root.add(itemnode);

        ItemView itemPanel = new ItemView();
        DefaultMutableTreeNode itemView = new DefaultMutableTreeNode(itemPanel);
        itemnode.add(itemView);
        jScrollPane2.setViewportView(itemPanel);

        DefaultMutableTreeNode reportnode = new DefaultMutableTreeNode("Reports");
        root.add(reportnode);

        DailySales dailySale = new DailySales();
        DefaultMutableTreeNode dailySaleNode = new DefaultMutableTreeNode(dailySale);
        reportnode.add(dailySaleNode);

        DailyTopQuantitySales dailyTopTenQuan = new DailyTopQuantitySales();
        DefaultMutableTreeNode dailyTopTenQuanNode = new DefaultMutableTreeNode(dailyTopTenQuan);
        dailySaleNode.add(dailyTopTenQuanNode);
        
        DailyTopValueSales dailyTopTenVal = new DailyTopValueSales();
        DefaultMutableTreeNode dailyTopTenValNode = new DefaultMutableTreeNode(dailyTopTenVal);
        dailySaleNode.add(dailyTopTenValNode);

        DailyTopCategorySales dailyTopTenCat = new DailyTopCategorySales();
        DefaultMutableTreeNode dailyTopTenCatNode = new DefaultMutableTreeNode(dailyTopTenCat);
        dailySaleNode.add(dailyTopTenCatNode);

        MonthlySales monthlySale = new MonthlySales();
        DefaultMutableTreeNode monthlySaleNode = new DefaultMutableTreeNode(monthlySale);
        reportnode.add(monthlySaleNode);

        MonthlyTopQuantitySales monthlyTopTenQuan = new MonthlyTopQuantitySales();
        DefaultMutableTreeNode monthlyTopTenQuanNode = new DefaultMutableTreeNode(monthlyTopTenQuan);
        monthlySaleNode.add(monthlyTopTenQuanNode);
        
        MonthlyTopValueSales monthlyTopTenVal = new MonthlyTopValueSales();
        DefaultMutableTreeNode monthlyTopTenValNode = new DefaultMutableTreeNode(monthlyTopTenVal);
        monthlySaleNode.add(monthlyTopTenValNode);

        MonthlyTopCategorySales monthlyTopTenCat = new MonthlyTopCategorySales();
        DefaultMutableTreeNode monthlyTopTenCatNode = new DefaultMutableTreeNode(monthlyTopTenCat);
        monthlySaleNode.add(monthlyTopTenCatNode);
        
        DefaultMutableTreeNode sale = new DefaultMutableTreeNode("Sale");
        root.add(sale);

        SetupSaleItem saleItemPanel = new SetupSaleItem();
        DefaultMutableTreeNode setUpSale = new DefaultMutableTreeNode(saleItemPanel);
        sale.add(setUpSale);
        
        Logout logOut = new Logout(this);
        DefaultMutableTreeNode logoutNode = new DefaultMutableTreeNode(logOut);
        root.add(logoutNode);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    // End of variables declaration//GEN-END:variables

    private JTree tree;
}
